//1.引入mangoose模块
const mongoose = require('mongoose')

//2.创建文章集合规则
const articleSchema = new mongoose.Schema({
  title: {
    type: String,
    maxlength: 20,
    minlength: 4,
    required: [true, '文章标题不能为空！']
  },
  author: {
    type: mongoose.Schema.Types.ObjectID,
    ref: 'User',
    required: [true, '作者不能为空！']
  },
  publishDate: {
    type: Date,
    default: Date.now,
    required: [true, '上传时间不能为空！']
  },
  cover: {
    type: String,
    default: null
  },
  content: {
    type: String,
  }
})

//3.根据规则创建集合
const Article = mongoose.model('Article', articleSchema)

//4.将集合规则作为模块成员导出
module.exports = {
  Article
}